This notebook has an objective to analyze athe information given by Argentinian government on the evolution of the current COVID19 pandemic.
The dataset used can be found at http://datos.salud.gob.ar/dataset/covid-19-casos-registrados-en-la-republica-argentina/archivo/fd657d02-a33a-498b-a91b-2ef1a68b8d16
It is a CSV file containing a row for each individual person that was suspected of having covid.
library(tidyr)
library(dplyr)
library(ggplot2)
library(magrittr)
library(leaflet)
library(rgdal)
cases <- read.csv("covidsampled.csv")
glimpse(cases)
## Rows: 43,429
## Columns: 26
## $ X <int> 3989910, 1792042, 889322, 864810, 17…
## $ id_evento_caso <int> 5360238, 3004024, 2025864, 1998247, …
## $ sexo <chr> "F", "M", "M", "M", "F", "F", "M", "…
## $ edad <dbl> 1, 29, 9, 23, 85, 21, 41, 3, 29, 92,…
## $ edad_años_meses <chr> "Años", "Años", "Años", "Años", "Año…
## $ residencia_pais_nombre <chr> "Argentina", "Argentina", "Argentina…
## $ residencia_provincia_nombre <chr> "Neuquén", "CABA", "CABA", "Buenos A…
## $ residencia_departamento_nombre <chr> "Confluencia", "COMUNA 01", "COMUNA …
## $ carga_provincia_nombre <chr> "Neuquén", "CABA", "CABA", "Buenos A…
## $ fecha_inicio_sintomas <chr> "2020-12-15", "2020-09-28", "2020-08…
## $ fecha_apertura <chr> "2020-12-18", "2020-09-29", "2020-08…
## $ sepi_apertura <int> 51, 40, 34, 34, 40, 33, 36, 48, 33, …
## $ fecha_internacion <chr> "", "", "", "", "", "", "", "2020-11…
## $ cuidado_intensivo <chr> "NO", "NO", "NO", "NO", "NO", "NO", …
## $ fecha_cui_intensivo <chr> "", "", "", "", "", "", "", "", "", …
## $ fallecido <chr> "NO", "NO", "NO", "NO", "NO", "NO", …
## $ fecha_fallecimiento <chr> "", "", "", "", "", "", "", "", "", …
## $ asistencia_respiratoria_mecanica <chr> "NO", "NO", "NO", "NO", "NO", "NO", …
## $ carga_provincia_id <int> 58, 2, 2, 6, 6, 78, 6, 6, 82, 2, 2, …
## $ origen_financiamiento <chr> "PĂºblico", "PĂºblico", "PĂºblico", "PĂºâ€¦
## $ clasificacion <chr> "Caso confirmado por criterio clinic…
## $ clasificacion_resumen <chr> "Confirmado", "Confirmado", "Confirm…
## $ residencia_provincia_id <int> 58, 2, 2, 6, 6, 78, 6, 6, 82, 2, 2, …
## $ fecha_diagnostico <chr> "", "2020-09-29", "2020-08-21", "202…
## $ residencia_departamento_id <int> 35, 1, 3, 760, 28, 21, 658, 791, 84,…
## $ ultima_actualizacion <chr> "2020-12-25", "2020-12-25", "2020-12…
Our first step is to clean up the Data.
Some people can be as old as 1000 years old, which is clearly incorrect. We will only consider those 100 years old or younger. We will format the date strings into a proper date type. We will not consider the cases who were discarded as not having Covid, however we will keep the suspicious cases and treat them as positives.
cases <- filter(cases, clasificacion_resumen != "Descartado")
cases <- filter(cases, edad < 100 )
cases$fecha_apertura <- as.Date(cases$fecha_apertura, "%Y-%m-%d")
cases$fecha_fallecimiento <- as.Date(cases$fecha_fallecimiento, "%Y-%m-%d")
length(cases$fallecido)
## [1] 19045
group_by(cases, residencia_provincia_nombre) %>% summarise(total = n()) %>% arrange(desc(total))
## # A tibble: 25 x 2
## residencia_provincia_nombre total
## <chr> <int>
## 1 Buenos Aires 7685
## 2 Santa Fe 1931
## 3 CABA 1800
## 4 CĂ³rdoba 1644
## 5 TucumĂ¡n 1201
## 6 Mendoza 729
## 7 Neuquén 482
## 8 RĂo Negro 405
## 9 Chubut 363
## 10 Chaco 354
## # … with 15 more rows
argentina <- readOGR(dsn = "ARG_adm", layer = "ARG_adm1", use_iconv=TRUE, encoding='UTF-8', stringsAsFactors=FALSE, verbose = FALSE)
cases_by_province <- group_by(cases, residencia_provincia_nombre) %>%
summarise(total = n()) %>%
filter(residencia_provincia_nombre != "SIN ESPECIFICAR") %>%
mutate(NAME_1 = residencia_provincia_nombre) %>%
mutate(NAME_1 = replace(NAME_1, NAME_1=="CABA","Ciudad de Buenos Aires"))
argentina@data <- left_join(argentina@data,cases_by_province, by = c("NAME_1"))
state_popup <- paste0("<strong>Estado: </strong>",
argentina$NAME_1,
"<br><strong>Casos: </strong>",
argentina@data$total)
pal <- colorQuantile("YlGn", NULL, n = 5)
leaflet(data = argentina) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = ~pal(total),
fillOpacity = 0.8,
color = "#BDBDC3",
weight = 1,
popup = state_popup)